package com.itheima.service.impl;

import cn.itheima.health.entity.QueryPageBean;
import cn.itheima.health.service.PermissionService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itheima.mapper.PermissionMapper;
import com.itheima.pojo.Permission;
import org.apache.curator.framework.api.BackgroundPathableQuietlyable;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Service
@Transactional
public class PermissionServiceImpl implements PermissionService {

    @Autowired
    private PermissionMapper permissionMapper;

    @Override
    public Map findPage(QueryPageBean queryPageBean) {
        Map map = new HashMap();
        PageHelper.startPage(queryPageBean.getCurrentPage(),queryPageBean.getPageSize());
        List<Permission> list = permissionMapper.findPage(queryPageBean.getQueryString());
        PageInfo<Permission> pageInfo = new PageInfo<>(list);
        map.put("list",pageInfo.getList());
        map.put("total",pageInfo.getTotal());
        return map;
    }

    @Override
    public void add(Permission permission) {
        permissionMapper.add(permission);
    }

    @Override
    public void edit(Permission permission) {
        permissionMapper.edit(permission);
    }

    @Override
    public void deletePermissionById(Integer id) {
        permissionMapper.deletePermissionById(id);
    }

    @Override
    public List<Permission> findPermissionAll() {
        return permissionMapper.findPermissionAll();
    }

    @Override
    public Map findPermissionIdsByRoleId(Integer id) {
        Map map = new HashMap();
        List<Permission> list = permissionMapper.findPermissionAll();
        Integer[] permissionIds = permissionMapper.findPermissionIdsByRoleId(id);
        map.put("list",list);
        map.put("permissionIds",permissionIds);
        return map;
    }
}
